#include "qinit.h"
#include <QDBusConnection>
#include <QDBusError>
#include <QCoreApplication>
#include <QList>
#include <QtGlobal>
#ifdef Q_OS_WIN32
#include <windows.h>
#endif
#include <QDebug>
#include <QLibrary>
#include "qinit.h"
#include "common.h"
#include "QInitMicro.h"
#include <QDBusMetaType>

QInit::QInit()
{
//    QDBusConnection connection = QDBusConnection::sessionBus();
//    QObject object;
//    handler = new QInitHandler(&object);
//    connection.registerObject("/", &object);
//    if(!connection.registerService(service_name))
//	{
//        qDebug() << "error:" << QDBusConnection::sessionBus().lastError().message();
//		exit(-1);
//	}

}


QList<QString> dll_list = {
    "Qt6Core",
    "Qt6Gui",
    "Qt6Network",
    "Qt6Xml",
    "Qt6Svg",
    "Qt6Sql",
    "Qt6Qml",
    "Qt6Quick",
    "Qt6Multimedia"
};


int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
//    qRegisterMetaType<char>("char");
//    qRegisterMetaType<char*>("char*");
//    qDBusRegisterMetaType<char*>();
    createDesktop("ls", "", "ls.desktop");
    // 加载动态库
    foreach(QString dll_name, dll_list)
    {
        QLibrary library(dll_name);
        if(!library.load())
        {
            qDebug() << "error: " << dll_name << " load fail";
        }
        qDebug() << library.fileName();
    }

    // 启动dbus服务
    QDBusConnection connection = QDBusConnection::sessionBus();
    QObject object;
    QInitHandler* handler = new QInitHandler(&object);
    connection.registerObject("/", &object);
    if(!connection.registerService(SERVICE_NAME))
    {
        qDebug() << "error:" << QDBusConnection::sessionBus().lastError().message();
        exit(-1);
    }
    return app.exec();
}

